﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data;

namespace Ewts.ashx
{
    /// <summary>
    /// 2015年6月21日 FIFA
    /// AutocompleteProduceMaterial 的摘要说明
    /// 根据outid 列出barcode中的物品
    /// 
    /// </summary>
    public class AutoProduceMaterial : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            StringBuilder items = new StringBuilder();
            DataTable dt = new DataTable();
            DataTable dt2 =new DataTable();
            string strwhere = "";



            if (!string.IsNullOrEmpty(context.Request["Outid"]))
            {
                string Outid = context.Request["Outid"];

                if (!string.IsNullOrEmpty(context.Request["goods"]))
                {
                    strwhere = "goodscode like '%" + context.Request["goods"].Trim() + "%' and OutStrorageID = " + Outid;
                }
                dt = new DataLib.BLL.BarCode().GetList(10, strwhere, "id").Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                     DataView dv=new DataView(dt);
                    dt2 = dv.ToTable(true, "goodsname","goodscode","goodsid");
                }
;
                if (dt2.Rows.Count > 0)
                {
                    items.Append("[");
                    for (int i = 0; i < dt2.Rows.Count; i++)
                    {
                        items.Append("{\"value\":\"");
                        items.Append(dt2.Rows[i]["goodsname"].ToString());
                        items.Append("\",\"label\":\"");
                        items.Append(dt2.Rows[i]["goodscode"].ToString());
                        items.Append("\",\"rubid\":\"");
                        items.Append(dt2.Rows[i]["goodsid"].ToString());
                        items.Append("\"},");

                    }
                    items.Remove(items.Length - 1, 1);
                    items.Append("]");

                }

            }
            context.Response.Write(items);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}